import 'package:animation/components/images/image_load.dart';
import 'package:animation/model/options_base.dart';
import 'package:animation/pages/other/videos/bilibili_page.dart';
import 'package:flutter/material.dart';

class UpdateList extends StatefulWidget {
  final List updateListInfo;
  const UpdateList({super.key, required this.updateListInfo});

  @override
  State<UpdateList> createState() => _UpdateListState();
}

class _UpdateListState extends State<UpdateList> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(OptionsBase().padding),
      child: GridView.builder(
          itemCount: widget.updateListInfo.length,
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: OptionsBase().imageColumns(context),
            crossAxisSpacing: OptionsBase().padding,
            mainAxisSpacing: OptionsBase().padding,
            childAspectRatio: 0.7,
          ),
          itemBuilder: (context, index) {
            return GestureDetector(
              onTap: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => BilibiliPage(
                              msg: widget.updateListInfo[index]['title'],
                              ssid: widget.updateListInfo[index]['season_id'],
                              cover: widget.updateListInfo[index]['cover'],
                            )));
              },
              child: Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5),
                    color: Theme.of(context).colorScheme.primaryContainer,
                    boxShadow: [
                      BoxShadow(
                        color: Theme.of(context).colorScheme.shadow,
                        offset: Offset(1, 2),
                        blurRadius: 2,
                      ),
                    ]),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(5),
                  child: Stack(
                    alignment: Alignment.bottomCenter,
                    children: [
                      Hero(
                        tag: widget.updateListInfo[index]['season_id'],
                        child: ImageLoad(
                            imageUrl: widget.updateListInfo[index]['cover']),
                      ),
                      Container(
                        padding: EdgeInsets.only(
                            left: 5, right: 5, top: 2, bottom: 2),
                        color: const Color.fromARGB(24, 158, 158, 158),
                        width: double.infinity,
                        child: Text(
                          widget.updateListInfo[index]['title'],
                          style: TextStyle(
                            color: Colors.white,
                          ),
                          overflow: TextOverflow.ellipsis,
                        ),
                      )
                    ],
                  ),
                ),
              ),
            );
          }),
    );
  }
}
